/*
 * my_lib.h
 *
 *  Created on: Nov 26, 2012
 *      Author: andrey
 */

#ifndef MY_LIB_H_
#define MY_LIB_H_

#include "main.h"
#ifdef CHIBIOS
#include <ch.h>
#endif

#include <stm32f4xx.h>
#include <stm32f4xx_gpio.h>
#include <stm32f4xx_rcc.h>

// number of SysClock ticks in one ms
#define MS_DIVIDER (CH_FREQUENCY / 1000)

#ifndef CHIBIOS
 int GetCurrentTime();
 void Delay(__IO uint32_t msDelay);
#else
 #define GetCurrentTime() chTimeNow()
 #define Delay(ms) chThdSleepMilliseconds(ms)
#endif

void TimingDelay_Decrement(void);

void turnPinOff(GPIO_TypeDef* GPIOx, uint32_t pinBits);
void turnPinOn(GPIO_TypeDef* GPIOx, uint32_t pinBits);

void enablePortClock(GPIO_TypeDef* GPIOx);
void mySTM_EVAL_LEDInit(uint32_t pin, GPIO_TypeDef* GPIOx);
char *portname(GPIO_TypeDef* GPIOx);
void Timing10ms();

#endif /* MY_LIB_H_ */
